﻿/// <reference path="jquery-1.5.1.min.js" />

$(function () {

    $("#commentSubmit").click(function () {
        var nickName = $("#userName").val();
        var email = $("#userMail").val();

        if (nickName == "") {
            EasyMessage("please input your nick name", "error", 10000);
            return false;
        }
        if (email == "") {
            EasyMessage("please input your email", "error", 10000);
            return false;
        }

        var reg = new RegExp("\n", "g");
        $("#comment").val($("#comment").val().replace(reg, "<br />"));

        $("#commentForm").submit();
    });


    $(".replyComment").click(function () {
                var comment = $.trim($(this).parent().prev().text());
                comment = "\n\n--------------------------------------------------------\n" + comment;
                $("#comment").val(comment);
                $("#comment").focus();

//        var replyBox = $(this).parent().parent();
//        var replyBoxHtml = $("<div></div>").append(replyBox.clone()).html();
//        replyBox.after("test");
    });


    $(".deleteReply").click(function () {
        var deleteCommentSpan = $(this);
        var commentId = $(this).attr("CommentId");
        if (commentId == "") {
            EasyMessage("invalid comment", "error", 6000);
        }

        $.post("/Admin/DeleteComment", { "commentId": commentId }, function (data) {
            if (data == "success") {
                EasyMessage("delete successful", "success", 6000);
                deleteCommentSpan.parent().parent().animate({
                    "height": "0"
                }, 300, function () {
                    deleteCommentSpan.parent().parent().remove();
                });
            }
            else {
                EasyMessage("delete failed", "error", 10000);
            }

        }, "json");
    });
});

